package com.want.buss.interfaces.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.want.buss.interfaces.dto.SpecialOfStoreParam;
import com.want.buss.interfaces.dto.SpecialOfTaskListParam;
import com.want.buss.interfaces.po.SpecialOfStore;
import com.want.buss.interfaces.po.SpecialOfTaskList;
import com.want.buss.interfaces.service.IAuditUserService;
import com.want.buss.interfaces.service.ISpecialOfStoreService;
import com.want.buss.interfaces.service.ISpecialOfTaskListService;
import com.want.buss.interfaces.utils.ResultVoUtils;
import com.want.buss.interfaces.vo.ResultVo;

/**
 * 
 * @author 00323357
 * @date   2018年12月12日
 */
@CrossOrigin
@RestController
public class SpecialOfTaskListController {
	// 定义一个LOGGER常量，用来打印log
	private  final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private ISpecialOfTaskListService specialOfTaskListService;
	
	@Autowired
	private ISpecialOfStoreService   specialOfStoreService;
	
	@Autowired
	private IAuditUserService   auditUserService;
	
	@RequestMapping(value="/audit/queryAuditList",method=RequestMethod.GET)
	public ResultVo queryAuditList(String empId){
		if (StringUtils.isEmpty(empId)) {
			return ResultVoUtils.error(0,"人员工号不能为空");
		}else{
			List<String> auditList= new ArrayList<String>();
			try {
				String empIdTemp = auditUserService.queryHrEmp(empId);
				if(StringUtils.isEmpty(empIdTemp)) {
				   return ResultVoUtils.error(0, "不是公司人员");
				}else {
					auditList = auditUserService.queryAuditUser(empId);
					//查询所有员工
					if(auditList.size() == 0) {
						auditList = auditUserService.queryAuditUser(null);
					}
				}
				return ResultVoUtils.success(auditList);
			} catch (Exception e) {
				logger.error("Exception e---"+e);
				return ResultVoUtils.error(0, "系统错误");
			}
		}
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/audit/querySpecialOfTaskList",method=RequestMethod.GET)
	public ResultVo querySpecialOfTaskList(SpecialOfTaskListParam specialOfTaskListParam){
		String validateMsg =validateSpecialOfTaskListParam(specialOfTaskListParam);
		if (validateMsg!="") {
			return ResultVoUtils.error(0,validateMsg);
		}else{
			try {
				List<SpecialOfTaskList> specialOfTaskList= specialOfTaskListService.querySpecialOfTaskList(specialOfTaskListParam);
				logger.info("specialOfTaskLists---"+specialOfTaskList);
				return ResultVoUtils.success(specialOfTaskList);
			} catch (Exception e) {
				logger.error("Exception e---"+e);
				return ResultVoUtils.error(0, "系统错误");
			}
		}
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/audit/querySpecialOfStore",method=RequestMethod.GET)
	public ResultVo querySpecialOfStore(SpecialOfStoreParam specialOfStoreParam){
		String validateMsg =validateSpecialOfStoreParam(specialOfStoreParam);
		if(validateMsg!="") {
			return ResultVoUtils.error(0, validateMsg);
		}else {
			try {
				List<SpecialOfStore> specialOfTaskList= specialOfStoreService.querySpecialOfStore(specialOfStoreParam);
				logger.info("specialOfTaskLists---"+specialOfTaskList);
				return ResultVoUtils.success(specialOfTaskList);
			} catch (Exception e) {
				logger.error("Exception e---"+e);
				return ResultVoUtils.error(0, "系统错误");
			}
		}
	}
	
	private String validateSpecialOfTaskListParam(SpecialOfTaskListParam specialOfTaskListParam) {
		String msg = "";
		if(StringUtils.isEmpty(specialOfTaskListParam.getJhId())) {
			msg = "人员工号不能为空";
		}
		return msg;
	}
	
	private String validateSpecialOfStoreParam(SpecialOfStoreParam specialOfStoreParam) {
		String msg = "";
		if(StringUtils.isEmpty(specialOfStoreParam.getSdNo())) {
			msg = "特陈申请编码不能为空";
		}else if(StringUtils.isEmpty(specialOfStoreParam.getStoreId())) {
			msg = "终端编码不能为空";
		}
		return msg;
	}
	
}
